package com.health.fragment;

import java.util.List;

import com.health.MainActivity_Menu_Admin;
import com.health.MainActivity_Menu_AdminDocter;
import com.health.NovaApplication;
import com.health.R;
import com.health.tablebean.BD_ORGANIZE_EMPLOYEE;
import com.health.tools.GlobalConts;
import com.health.tools.SPUtil;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 体检 --登录
 * 
 * @author nova
 *
 */
public class Main_admin_loginFragment extends NovaFragment implements OnClickListener {

	private Button loginBtn;
	private Button cancelBtn;
	private EditText ed_name;
	private EditText ed_pwd;
	private View baseView;
	@Override
	public View findViews(LayoutInflater inflater) {

		baseView = inflater.inflate(R.layout.mainactivity_login_admin, null);

		findViews(baseView);
		setData();
		return baseView;
	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		loginBtn.setOnClickListener(this);
		cancelBtn.setOnClickListener(this);

	}


	public void findViews(View view) {
		ed_name = (EditText) baseView.findViewById(R.id.exam_login_name);
		ed_pwd = (EditText) baseView.findViewById(R.id.exam_login_pwd);
		loginBtn = (Button) baseView.findViewById(R.id.exam_login_btn);
		cancelBtn = (Button) baseView.findViewById(R.id.exam_login_cancel);

	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.exam_login_btn:
			List<BD_ORGANIZE_EMPLOYEE> doctors=NovaApplication.fdbmanger.findAllByWhere(BD_ORGANIZE_EMPLOYEE.class, "NAME= '"+ed_name.getText().toString()+"' AND "+"PASSWORD='"+ed_pwd.getText().toString()+"'");
			if(TextUtils.isEmpty(ed_name.getText())||TextUtils.isEmpty(ed_pwd.getText())){
				GlobalConts.showToast(getActivity(), "用户名或密码为空");
			}else if (doctors.size()>0) {
				Intent intent = new Intent(getActivity(), MainActivity_Menu_AdminDocter.class);
				startActivity(intent);
			}else if((ed_name.getText().toString()).equals("admin")&&(ed_name.getText().toString()).equals("admin")){
				Intent intent = new Intent(getActivity(), MainActivity_Menu_Admin.class);
				intent.putExtra("admin", "admin");
				startActivity(intent);
			}else{
				GlobalConts.showToast(getActivity(), "用户名或密码不正确");
			}
			
			break;
		case R.id.exam_login_cancel:
			getActivity().finish();
			break;
	

		default:
			break;
		}

	}

	@Override
	public void setData() {
		ed_name.setText( SPUtil.getstr_jdr(getActivity()));
		ed_pwd.setText(SPUtil.getstr_jdpassward(getActivity()));//sp.getString("str_jdpassward", "")
	}

}
